package 周赛;

import org.junit.Test;

import java.math.BigInteger;
import java.util.Arrays;
import java.util.Collection;
import java.util.Comparator;

public class 找出数组中第k大元素 {

    public String kthLargestNumber(String[] nums, int k) {
        Arrays.sort(nums, new Comparator<String>() {
            @Override
            public int compare(String s1, String s2) {
                if (s1.length()!=s2.length())
                    return s2.length()-s1.length();
                else {
                    for (int i=0;i<s1.length();++i){
                        if (s1.charAt(i)!=s2.charAt(i)){
                            return s2.charAt(i)-s1.charAt(i);
                        }
                    }
                }
                return 0;
            }
        });
        return nums[k-1];
    }
    @Test
    public void test(){
        String[] nums={"5","2","4","10","121","15","456"};
//        for (int i = 0; i < nums.length-1; i++) {
//            if (nums[i].compareTo(nums[i+1])>0){
//                String temp=nums[i];
//                nums[i]=nums[i+1];
//                nums[i+1]=temp;
//            }
//        }
        Arrays.sort(nums);
        for (int i = 0; i < nums.length; i++) {
            System.out.println(nums[i]);
        }
    }
}
